<?php

namespace App\Models\Common;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasOne;

class FsCompanySecondDepartmentModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'fs_company_second_department';

    protected $fillable = [
        'fsCompanyId',
        'secondDepartmentId',
        'secondDepartmentName',
        'businessType'
    ];

    public static function add(
        int $fsCompanyId,
        string $secondDepartmentId,
        string $secondDepartmentName,
        int $businessType
    ) {
        return self::query()->updateOrCreate([
            'fsCompanyId'        => $fsCompanyId,
            'secondDepartmentId' => $secondDepartmentId,
            'businessType'       => $businessType
        ], ['secondDepartmentName' => $secondDepartmentName]);
    }

    const BUSINESS_TYPE_CHECK = 1;  //品控稽核


    /**
     * @return HasOne
     */
    public function fsCompanyRel(): HasOne
    {
        return $this->hasOne(FsCompanyModel::class, 'id', 'fsCompanyId');
    }
}
